package cn.xmkeshe.controller;

import cn.xmkeshe.back.ICommentServiceBack;
import cn.xmkeshe.front.ICommentServiceFront;
import cn.xmkeshe.model.Comment;
import cn.xmkeshe.utils.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
public class CommentController {

  @Resource
  private ICommentServiceFront iCommentServiceFront;
  @Resource
  private ICommentServiceBack iCommentServiceBack;

//  跳转到意见反馈页面
  @RequestMapping("/pages/front/comment/commentPre")
  @Log(operationName = "意见反馈前",operationType = "用户")
  public String commentPre(){
    return "/pages/front/comment/comment";
  }

//  用户意见反馈
  @RequestMapping("/pages/front/comment/comment")
  @ResponseBody
  @Log(operationName = "意见反馈",operationType = "系统")
  public String comment(Comment comment){
    String flag = "error";
    comment.setType(1);
    if(iCommentServiceFront.comment(comment)){
      return "success";
    }
    return flag;
  }

//  后台查询意见反馈
//  用户意见
  @RequestMapping("/pages/back/comment/commentListPre")
  @Log(operationName = "查看用户意见反馈前",operationType = "管理员")
  public String commentListPre(){
    return "/pages/back/customer/comment";
  }

  @RequestMapping("/pages/back/comment/commentList")
  @ResponseBody
  @Log(operationName = "用户意见反馈数据",operationType = "系统")
  public Map<String, Object> list(HttpServletRequest request){

    Map<String,Object> map = new HashMap<String,Object>();
    map.put("code",0);//解析接口状态，必须这样写
    map.put("msg","加载中");//解析提示文本
    map.put("data",iCommentServiceBack.findAll());//    解析数据列表
    map.put("count",100);//    解析数据长度
    System.out.println(map);
    return map;
  }

//  员工意见
//  添加员工意见
  @RequestMapping("/pages/back/comment/staffCommentPre")
  @Log(operationName = "添加员工意见前",operationType = "管理员")
  public String staffCommentListPre(){
    return "/pages/back/admin/addComment";
  }

  @RequestMapping("/pages/back/comment/comment")
  @ResponseBody
  @Log(operationName = "添加员工意见",operationType = "系统")
  public String StaffComment(Comment comment){
    String flag = "error";
    comment.setType(2);
    if(iCommentServiceBack.comment(comment)){
      return "success";
    }
    return flag;
  }


//  查看员工意见
  @RequestMapping("/pages/back/comment/staffPre")
  @Log(operationName = "查看员工意见前",operationType = "管理员")
  public String StaffCommentListPre(){
    return "/pages/back/admin/comment";
  }

  @RequestMapping("/pages/back/comment/staffCommentList")
  @ResponseBody
  @Log(operationName = "员工意见数据",operationType = "系统")
  public Map<String, Object> StaffCommentList(HttpServletRequest request){

    Map<String,Object> map = new HashMap<String,Object>();
    map.put("code",0);//解析接口状态，必须这样写
    map.put("msg","加载中");//解析提示文本
    map.put("data",iCommentServiceBack.findAllStaff());//    解析数据列表
    map.put("count",100);//    解析数据长度
    System.out.println(map);
    return map;
  }
}
